Skip to content

docs: add Google-style docstrings to public api/services/utils/models…#119

Open
clean6378-max-it wants to merge 4 commits into
masterfrom
docs/api-layer-docstrings
Open

docs: add Google-style docstrings to public api/services/utils/models…#119
clean6378-max-it wants to merge 4 commits into
masterfrom
docs/api-layer-docstrings

Conversation

@clean6378-max-it

@clean6378-max-it clean6378-max-it commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Closes #108

Summary

Add Google-style docstrings to the remaining undocumented public surface across api/, services/, utils/, and models/. Fills gaps in route handlers, summary-cache helpers, workspace path overrides, display-bubble accessors, and all from_dict classmethods on core model types.

Sprint item #5 (Tuesday PR 1 of 2, 3 pt). Docstrings only — no functional changes.

Problem

Public functions and model parsers across the web API and CLI export paths lacked parameter, return, and side-effect documentation, slowing onboarding and review.

Changes

api/ (6 files)

  • Route handlers: workspaces.py, search.py, composers.py, config_api.py, logs.py, pdf.py
  • Nested PDFDoc class and header/footer methods in pdf.py

services/

  • summary_cache.py: nocache_enabled and all cache get/set helpers

utils/

  • workspace_path.py: set_workspace_path_override, get_workspace_path_override
  • display_bubble.py: display_bubble_metadata, display_bubble_tool_calls

models/

  • from_dict on Composer, WorkspaceLocalComposer, Bubble, Workspace, CliSessionMeta, ExportEntry

Key files that already had docstrings (workspace_listing.py, workspace_resolver.py, export_api.py, etc.) were left unchanged.

Out of scope

Test plan

  • Public docstring scan — 0 missing per acceptance criteria
  • mypy . — pass
  • pytest — 468 passed (7 PDF tests skip/fail locally without fpdf installed)
  • Full CI pytest / ruff on reviewer environment

Acceptance criteria

  • Public functions in api/, services/, utils/ documented (summary, Args, Returns)
  • Model public classes retain class docstrings; from_dict classmethods documented
  • Google style throughout
  • No functional code changes
  • mypy green

Summary by CodeRabbit

  • Documentation
    • Expanded API endpoint documentation across workspaces, logs, search, config, composers, and PDF generation (request/response shapes, query parameters, and documented status/error behavior).
    • Added/expanded detailed docstrings for model parsing/validation methods, including documented validation/raise conditions.
    • Improved utility helper docstrings, including workspace path override semantics and display metadata/tool-call helpers.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a52c34d1-08a3-406d-8568-a3061d83433c

📥 Commits

Reviewing files that changed from the base of the PR and between efd50a0 and cbbe594.

📒 Files selected for processing (7)
  • api/composers.py
  • api/config_api.py
  • api/pdf.py
  • api/search.py
  • api/workspaces.py
  • models/cli_session.py
  • services/summary_cache.py
✅ Files skipped from review due to trivial changes (7)
  • models/cli_session.py
  • api/search.py
  • api/pdf.py
  • api/composers.py
  • api/config_api.py
  • services/summary_cache.py
  • api/workspaces.py

📝 Walkthrough

Walkthrough

Docstrings are added to public functions and classmethods across api/, models/, services/, and utils/ packages. No functional logic, control flow, routing, or error handling was changed. The additions cover Flask route handlers, model from_dict classmethods, summary cache read/write helpers, and utility functions.

Changes

Docstring additions across api/, models/, services/, and utils/

Layer / File(s) Summary
API route handler docstrings
api/composers.py, api/config_api.py, api/logs.py, api/pdf.py, api/search.py, api/workspaces.py
Docstrings added to Flask route handlers documenting endpoint paths, query/body parameters, response JSON shapes, and HTTP status codes for error conditions (400, 404, 500). PDFDoc.header and PDFDoc.footer also gain inline docstrings. The workspaces.py import of workspace_resolver is simplified to remove lookup_workspace_display_name from imported names.
Model from_dict classmethod docstrings
models/cli_session.py, models/conversation.py, models/export.py, models/workspace.py
Docstrings added to from_dict classmethods on CliSessionMeta, Composer, WorkspaceLocalComposer, Bubble, ExportEntry, and Workspace, documenting raw input, return types, and SchemaError conditions for missing or malformed required fields.
Service cache function docstrings
services/summary_cache.py
Docstrings added to nocache_enabled and all six cache functions (get_cached_projects, set_cached_projects, get_cached_composer_id_to_ws, set_cached_composer_id_to_ws, get_cached_tab_summaries, set_cached_tab_summaries), documenting fingerprint matching, cache hit/miss behavior, and persisted payload shapes.
Utility function docstrings
utils/display_bubble.py, utils/workspace_path.py
Docstrings added to display_bubble_metadata, display_bubble_tool_calls (documenting fallback behavior for missing metadata), and set_workspace_path_override, get_workspace_path_override (documenting override semantics and thread-safe lock-protected access).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐇 Hop hop, through the code I go,
Adding words to help the devs know,
Each function now has a tale to tell,
Parameters, returns—documented well!
No logic changed, just clarity shines,
A rabbit's gift in docstring lines. 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR substantially addresses the core requirement of issue #108 by adding Google-style docstrings to public functions in api/, services/, utils/, and models/. However, the PR objectives document identifies several unresolved issues from code review: indentation error in cli_session.py, non-standard section headers in search.py/config_api.py/workspaces.py/pdf.py, incomplete parameter documentation, and missing blank lines in composers.py. Address the documented review findings: fix indentation in cli_session.py Raises section, standardize all non-Args/Returns/Raises headers to Google style, complete parameter documentation for nocache_enabled and list_workspaces, document results key in search 500 response, and add PEP 8 blank line in composers.py.
Out of Scope Changes check ⚠️ Warning The PR introduces a minor out-of-scope change: narrowing the import in api/workspaces.py to remove lookup_workspace_display_name. This import modification is not documentation-related and was not mentioned in the PR objectives or linked issue #108. Revert the import narrowing in api/workspaces.py to only include docstring additions, or provide justification for the functional change if it is intentional.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding Google-style docstrings to public functions and classes across api/, services/, utils/, and models/ modules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/api-layer-docstrings

Comment @coderabbitai help to get the list of available commands.

@clean6378-max-it clean6378-max-it self-assigned this Jun 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/composers.py`:
- Around line 131-139: The docstring for the function that fetches a composer by
ID (starting with "Fetch one composer by ID") has an inaccurate Returns section.
The current text states "404 when not found or schema drift blocks serving" but
schema drift is actually logged and skipped before attempting the global
fallback, so it does not block serving and is not a 404 condition. Update the
Returns documentation to accurately describe that a 404 only occurs when the
composer is not found in either per-workspace or global storage, and clarify
that schema drift issues are handled gracefully through logging and the fallback
mechanism.

In `@api/logs.py`:
- Around line 33-38: Update the docstring for the handler function to accurately
reflect the actual return format. The Returns section currently documents a bare
JSON array, but the handler actually wraps the log summaries in a logs object.
Change the documentation to specify that the response is {"logs": [JSON array of
log summary objects]} instead of just the array itself, so the docstring matches
the actual implementation behavior.

In `@api/pdf.py`:
- Around line 50-56: The docstring for the `generate_pdf()` function is
misleading about the request/response contract. Since the function defaults
missing `markdown` and `title` values instead of rejecting them, the docstring
should not describe them as required body parameters. Additionally, since the
function only emits 500 JSON errors and does not validate or return 400 errors,
the docstring should be updated to reflect only the actual error responses that
can occur. Revise the docstring to accurately describe that `markdown` and
`title` are optional with default values, and update the error documentation to
mention only 500 errors.

In `@api/workspaces.py`:
- Around line 169-179: The docstring for the tabs listing function is incomplete
and inaccurate. Update the Args section to document that `global` is also a
valid workspace_id value (in addition to storage folder names and
cli:<project_id>). Additionally, update the Returns section to clarify that the
helper function can return 200 with an empty tabs list ({"tabs": []}) even when
sqlite3.Error exceptions occur upstream, rather than only documenting 500 on
failure.

In `@models/cli_session.py`:
- Around line 20-30: The docstring for the Raises section in the function only
documents that SchemaError is raised when latestRootBlobId is missing or not a
string, but the require_truthy validation function also rejects falsey/empty
values (like empty strings, None, etc.) before the type check occurs. Update the
error description in the Raises section of the docstring to include falsey
values in the validation contract, so it accurately reflects all conditions
under which SchemaError is raised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 78b2c72f-f7b1-4177-99c2-07ca269199fb

📥 Commits

Reviewing files that changed from the base of the PR and between ae468e9 and b1b04be.

📒 Files selected for processing (13)
  • api/composers.py
  • api/config_api.py
  • api/logs.py
  • api/pdf.py
  • api/search.py
  • api/workspaces.py
  • models/cli_session.py
  • models/conversation.py
  • models/export.py
  • models/workspace.py
  • services/summary_cache.py
  • utils/display_bubble.py
  • utils/workspace_path.py

Comment thread api/composers.py
Comment thread api/logs.py
Comment thread api/pdf.py
Comment thread api/workspaces.py
Comment thread models/cli_session.py
@clean6378-max-it

Copy link
Copy Markdown
Collaborator Author

@CodeRabbit, please review this PR in more depth

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
gh pr diff 119 --repo cppalliance/cppa-cursor-browser

Length of output: 19055


🏁 Script executed:

#!/bin/bash
# Check actual module path for validate_workspace_path
fd "path_validation.py" .
grep -rn "validate_workspace_path" --include="*.py" -l

# Check search type values in search.py
cat -n api/search.py

# Verify get_composer 404 behavior on schema drift
cat -n api/composers.py

# Check nocache env var truthy values in summary_cache.py
grep -n "CURSOR_CHAT_BROWSER_NOCACHE" services/summary_cache.py -A 5

# Check require_non_empty_str_fields call in export.py to verify documented fields
cat -n models/export.py

# Check CliSessionMeta indentation in docstring
cat -n models/cli_session.py

Length of output: 21084



@clean6378-max-it — here is a thorough review of every changed file.


Overall Assessment

The intent is good and most docstrings are accurate. There are one confirmed indentation defect, four non-Google-style section headers (the main systemic issue), and several minor omissions. No functional code was changed, so the risk is low, but the issues below reduce the quality of the very documentation this PR is meant to improve.


1. models/cli_session.py — Indentation bug in Raises (Lines 29–30)

Confirmed defect. The continuation line sits at the same indent level as SchemaError: instead of being indented 4 spaces further, which breaks Google-style rendering in Sphinx/pydoc.

# Current (wrong — continuation at 12 sp, same as label)
        Raises:
            SchemaError: When ``latestRootBlobId`` is missing, falsey (e.g.
            empty string or ``None``), or not a string.

# Fixed (continuation at 16 sp)
        Raises:
            SchemaError: When ``latestRootBlobId`` is missing, falsey (e.g.
                empty string or ``None``), or not a string.

2. Non-Google-style section headers (4 files)

Google-style docstrings only recognise Args:, Returns:, Raises:, Note:, Example:, etc. as top-level sections. The following docstrings introduce ad-hoc prose sections that violate this:

File Function Non-standard header
api/search.py search Query params:
api/config_api.py set_workspace Body:
api/workspaces.py get_workspace_tabs Query params:
api/pdf.py generate_pdf Body (optional):

The fix is to fold the request parameters into the standard Args: section (as is done for path parameters in get_workspace and get_workspace_tab) or into a Note: section if you prefer to keep them separate from code arguments:

# api/search.py — example fix
    Args:
        q: Search query string (required; 400 returned when empty).
        type: Filter scope``all`` (default), ``chat``, or ``composer``.

3. services/summary_cache.pynocache_enabled: vague env-var description

The docstring says "True when bypass is requested or CURSOR_CHAT_BROWSER_NOCACHE is set" but the code (confirmed lines 40–42) checks for the values "1", "true", and "yes". Just saying "is set" implies any non-empty value works (e.g., "false" would not bypass, but a reader would think it does).

# Suggested
    Returns:
        True when bypass is requested or ``CURSOR_CHAT_BROWSER_NOCACHE``
        is set to ``"1"``, ``"true"``, or ``"yes"`` (case-insensitive).

4. api/search.pysearch: 500 body also includes "results": []

The code at line 69 returns {"error": "Search failed", "results": []} on the 500 path (the results key is present even on failure). The docstring only documents the 400/500 statuses but omits the results: [] always present in error responses, which is a useful client contract to know.


5. api/workspaces.pylist_workspaces: nocache param not in Args:

list_workspaces has no Args: section, yet it honours ?nocache=1. Since get_workspace_tabs does document its query params (even if in a non-standard way), this creates an inconsistency. Suggest adding a minimal Args: section:

    Args:
        nocache: When ``1``, bypass the summary disk cache.

6. api/composers.py — Missing blank line between route handlers (pre-existing, but visible in diff)

The diff shows the closing line of list_composers and the @bp.route decorator for get_composer on consecutive lines with no blank line between them. PEP 8 requires two blank lines between top-level definitions. This is a pre-existing issue exposed by the diff context.

        return json_response({"error": "Failed to get composers"}, 500)
                                                                         # ← missing blank line
`@bp.route`("/api/composers/<composer_id>")

What is Accurate ✓

These items were verified against the actual implementation and are correct:

  • get_composer returning 404 (not 500) on global-storage schema drift (confirmed line 240)
  • ExportEntry.from_dict required fields log_id, title, workspace (confirmed line 48)
  • :func:utils.path_validation.validate_workspace_path`` module path (file utils/path_validation.py exists)
  • search type values all | chat | composer (matches module-level comment and branch logic)
  • Env-var name CURSOR_CHAT_BROWSER_NOCACHE in nocache_enabled (confirmed lines 6–7 of module docstring and line 39)
  • CliSessionMeta.from_dict Raises description of the three failure modes (falsey, missing, non-string)

Summary of required fixes (prioritised):

Priority File Issue
🔴 Must models/cli_session.py Raises continuation indentation
🟡 Should api/search.py, api/config_api.py, api/workspaces.py, api/pdf.py Replace Query params: / Body: with Args:
🟡 Should services/summary_cache.py Specify accepted env-var values
🟢 Nice api/search.py Document "results": [] in 500 body
🟢 Nice api/workspaces.py Add Args: to list_workspaces
🟢 Nice api/composers.py Add missing blank line between routes

@clean6378-max-it

Copy link
Copy Markdown
Collaborator Author

all deep review findings aree addressed @CodeRabbit?

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get the latest diff to check all flagged items
gh pr diff 119 --repo cppalliance/cppa-cursor-browser

Length of output: 22456



@clean6378-max-it — yes, every finding from the deep review is now addressed. Here's the verification:

# Finding File Status
🔴 Raises continuation indentation models/cli_session.py ✅ Fixed — continuation line now indented 4 extra spaces
🟡 Query params:Args: api/search.py ✅ Fixed — q and type in Args:
🟡 Body:Args: api/config_api.py ✅ Fixed — path in Args:
🟡 Query params:Args: api/workspaces.py (get_workspace_tabs) ✅ Fixed — workspace_id, summary, nocache in Args:
🟡 Body (optional):Args: api/pdf.py ✅ Fixed — markdown and title in Args:
🟡 Env-var accepted values vague services/summary_cache.py ✅ Fixed — now specifies "1", "true", "yes" (case-insensitive)
🟢 500 body missing "results": [] api/search.py ✅ Fixed — documented in Returns:
🟢 list_workspaces missing Args: api/workspaces.py ✅ Fixed — nocache added to Args:
🟢 Missing blank line between routes api/composers.py ✅ Fixed — two blank lines now present

The PR looks good to merge from a documentation quality standpoint. 🐇✨

Comment thread api/workspaces.py
infer_workspace_name_from_context,
lookup_workspace_display_name,
)
from services.workspace_resolver import infer_workspace_name_from_context

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1): it is the cleanup your own PR body lists as out of scope, so it contradicts "docstrings only, not function changes"
2): #118 is still open and remove this exact same import, so whichever merges first makes the other conflict on this line. Recommend pulling this hunk out of #119 and letting #118 own the import cleanup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cppa-cursor-browser: Public modules — add docstrings to api/ layer functions

2 participants